#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<stack>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e5+100;
typedef long long LL;
const LL mod=1e9+7;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
vector<LL>g[maxn];
LL dfn[maxn],low[maxn],w[maxn],tot=0;
LL col[maxn],cnt=0,neww[maxn];
stack<LL>s;
bool instack[maxn];
map<LL,LL>map1[maxn];
void tarjan(LL u){
    dfn[u]=low[u]=++tot;
    s.push(u);instack[u]=true;
    for(LL i=0;i<g[u].size();i++){
        LL v=g[u][i];
        if(!dfn[v]){
            tarjan(v);
            low[u]=min(low[u],low[v]);
        }
        else if(instack[v]) low[u]=min(low[u],dfn[v]);
    }
    if(dfn[u]==low[u]){
        cnt++;
        LL y;
        do{
            y=s.top();
            col[y]=cnt;
            neww[cnt]=min(neww[cnt],w[y]);
            map1[cnt][w[y]]++;
            instack[y]=false;
            s.pop();
        }while(y!=u);
    }
}
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  memset(neww,0x3f,sizeof(neww));
  LL n;cin>>n;
  for(LL i=1;i<=n;i++) cin>>w[i];
  LL m;cin>>m;
  for(LL i=1;i<=m;i++){
    LL u,v;cin>>u>>v;
    g[u].push_back(v);
  }
  for(LL i=1;i<=n;i++){
     if(!dfn[i]){
        tarjan(i);
     }
  }
  LL ans=0;
  for(LL i=1;i<=cnt;i++){
    ans+=neww[i];
  }
  cout<<ans<<" ";
  LL f=1;
  for(LL i=1;i<=cnt;i++){
     f=(f%mod*map1[i][neww[i]]%mod)%mod;
  }
  cout<<f<<"\n";
return 0;
}
